#include"RingQueue.hpp"
#include<pthread.h>
#include<unistd.h>

void* comsumer(void* args)
{
    RingQueue<int>* rq = static_cast<RingQueue<int>*>(args);
    while(1)
    {
        int data = 0;
        rq->Pop(&data);
        std::cout << "消费了一个数据:" << data << std::endl;
    }
    return (void*)0;
}

void* productor(void* args)
{
    RingQueue<int>* rq = static_cast<RingQueue<int>*>(args);
    int data = 1;
    while(1)
    {
        sleep(1);
        rq->EnQueue(data);
        std::cout << "生产了一个数据:" << data << std::endl;
        data++;
    }
    return (void*)0;
}

int main()
{
    RingQueue<int>* rq = new RingQueue<int>();
    pthread_t c, p;
    pthread_create(&c, nullptr, comsumer, (void*)rq);
    pthread_create(&p, nullptr, productor, (void*)rq);
    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
    delete rq;

    return 0;
}